var makeRss = function(obj) {
    var rss_link = 'http://diycity.kr/rss/' + $(obj).attr('value');
    $('#rss_link').attr('href', rss_link);
    $('#rss_link').text(rss_link);
}


var coord2addr =
    {
	apikey: "459c244ff059e0d3a7fc6b0d1e7b3127edec7423",
	init : function()
	{
	},

	pingSearch : function(lat, lng)
	{
	    if (lat && lng)
	    {
		coord2addr.s = document.createElement('script');
		coord2addr.s.type ='text/javascript';
		coord2addr.s.charset ='utf-8';
		coord2addr.s.src = 'http://apis.daum.net/maps/coord2addr?apikey=' + coord2addr.apikey +
		    '&output=json&format=simple&callback=coord2addr.pongSearch&inputCoordSystem=WGS84&latitude=' + lat + '&longitude=' + lng;
		document.getElementsByTagName('head')[0].appendChild(coord2addr.s);
	    }
	},
	// 검색 결과를 뿌리는 함수 
	pongSearch : function(z)
	{
	    var fullName = z.name1 + " " + z.name2 +" "+z.name3;
	    $("#address1").text(z.name1);
	    $("#add1").attr('value', z.name1);

	    $("#address2").text(z.name1 + " " + z.name2);
	    $("#add2").attr('value', z.name1 + "/" + z.name2);

	    $("#address3").text(fullName);
	    $("#add3").attr('value', z.name1 + "/" + z.name2 + "/" + z.name3);

	    var rss_link = 'http://diycity.kr/rss/' + $("#add3").attr('value');
	    $('#rss_link').attr('href', rss_link);
	    $('#rss_link').text(rss_link);


	    $("#where").text(fullName);
	},
	// HTML태그 안 먹게 하는 함수
	escapeHtml : function(str) 
	{
	    str = str.replace(/&amp;/g, "&");
	    str = str.replace(/&lt;/g, "<");
	    str = str.replace(/&gt;/g, ">");
	    return str;
	},
	// HTML태그 삭제하는 함수
	stripHTMLtag : function(string) {
	    var objStrip = new RegExp();
	    objStrip = /[<][^>]*[>]/gi;
	    return string.replace(objStrip, "");
	},
	// 특정 좌표에 마커 추가
	addMark : function(lat, lng)
	{
	    var point = new DLatLng(lat, lng);
	    var mark = new DMark(point);
	    map.addOverlay(mark);
	    map.setCenter(point, 2);
	}
    };

var local_alert = {
    init: function(qry) {
	var encoded_qry = encodeURI(qry);
	$.getJSON("lib/geo_code_proxy.php?q=" + encoded_qry,
		  function(data) {
		      coord2addr.pingSearch(data.lat, data.lng);
		  });
    }
};